function SetUp(ply,header,id,encoded,data)

	ply.stand = {}
	ply.stand.stand = {}
	ply.stand.price = {}

	for k,v in pairs(data.stand) do

		ply.stand.stand[k] = v

	end

	for k,v in pairs(data.price) do
	
		ply.stand.price[k] = v

	end
	
	for k,v in pairs(data.stand) do

		GiveRes(ply,k,-v)

	end

	ply:SetNWBool("stand",true)
	ply:Freeze(true)
	
	local stand = ents.Create("da_marketstand")
	stand:SetPos(ply:GetPos() + Vector(ply:GetAngles():Forward().x * 64,ply:GetAngles():Forward().y * 64,0))
	stand:SetAngles(ply:GetAngles())
	stand:SetNWEntity("owner",ply)
	stand:SetNWString("title",data.text)
	stand:Spawn()
	
	ply:SetNWEntity("stande",stand)
	
	umsg.Start("standremovemenu",ply)
	umsg.End()


end
datastream.Hook("standsetup",SetUp)

function Stand(ply,key)

	if (key == IN_ZOOM) then
	
		if (ply:GetNWBool("stand") == nil or ply:GetNWBool("stand") == false) then

			umsg.Start("standmenu",ply)
			umsg.End()
		
		end
	
	end

end
hook.Add("KeyPress","Stand",Stand)

function GetStand(ply)

	for k,v in pairs(ents.GetAll()) do

		if (v:GetClass() == "da_marketstand") then
		
			if (v:GetNWEntity("owner") == ply) then
			
			return v
			
			end
		
		end
	
	end

end

function BuyStand(ply,cmd,args)

local item = args[1]
local amount = args[2]

local owner = ply:GetNWEntity("standbuy"):GetNWEntity("owner")

owner.stand.stand[item] = owner.stand.stand[item] - amount

GiveRes(owner,"gold",amount * owner.stand.price[item])
GiveRes(ply,"gold",-(amount * owner.stand.price[item]))
GiveRes(ply,item,amount)

end
concommand.Add("BuyStand",BuyStand)

function RemoveStandMenu(ply,cmd,args)

	for k,v in pairs(ply.stand.stand) do

		GiveRes(ply,k,v)

	end

	ply:SetNWBool("stand",false)
	ply:Freeze(false)
	GetStand(ply):Remove()

end
concommand.Add("RemoveStandMenu",RemoveStandMenu)
